package crivia.ecp.carry.em;

import crivia.ecp.common.ECR;
import crivia.json.common.JSONSwitcher;
import crivia.txt.sc.RK;

public class EditerController {
	
	public enum Type {
		Input(Type_Input)
		,Select(Type_Select)
		,Browser(Type_Browser)
		,TimePicker(Type_TimePicker)
		;
		private final String s;
		Type(String s){this.s=s;}
		@Override
		public String toString() {return s;}
	}

	private static final String Type_Input = "input";
	private static final String Type_Select = "select";
	private static final String Type_Browser = "browser";
	private static final String Type_TimePicker = "timePicker";

	public EditerController(String key, Type type, String defaultValue,
			String defaultText, boolean isRequird, String requirdString,
			int requirdStringLevel) {
		super();
		this.key = key;
		this.type = type;
		this.defaultValue = defaultValue;
		this.defaultText = defaultText;
		this.isRequird = isRequird;
		this.requirdString = requirdString;
		this.requirdStringLevel = requirdStringLevel;
	}
	
	

	public EditerController() {
		super();
	}



	private String key;
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}
	private Type type;
	public Type getType() {
		return type;
	}
	public void setType(Type type) {
		this.type = type;
	}
	private String defaultValue;
	public String getDefaultValue() {
		return defaultValue;
	}
	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}
	private String defaultText;
	public String getDefaultText() {
		return defaultText;
	}
	public void setDefaultText(String defaultText) {
		this.defaultText = defaultText;
	}
	private boolean isRequird;
	public boolean isRequird() {
		return isRequird;
	}
	public void setRequird(boolean isRequird) {
		this.isRequird = isRequird;
	}
	private String requirdString;
	public String getRequirdString() {
		return requirdString;
	}
	public void setRequirdString(String requirdString) {
		this.requirdString = requirdString;
	}
	private String requirdStringScript;
	public String getRequirdStringScript() {
		return requirdStringScript;
	}
	public EditerController setRequirdStringScript(String requirdStringScript) {
		this.requirdStringScript = requirdStringScript;
		return this;
	}
	private int requirdStringLevel;
	public int getRequirdStringLevel() {
		return requirdStringLevel;
	}
	public void setRequirdStringLevel(int requirdStringLevel) {
		this.requirdStringLevel = requirdStringLevel;
	}
	
	
	@Override
	public String toString() {
		if (ECR.hasCondition(requirdStringScript)){
			String script = RK.rk(23);
			setRequirdString(script);
			return JSONSwitcher.toJSON(this,"requirdStringScript")
				.replaceAll("[{] '", "{ ")
				.replaceAll("' : ", " : ")
				.replaceAll(" , '", " , ")
				.replaceAll("'"+script+"'", "function(){"
					+requirdStringScript+"}");
		} else {
			return JSONSwitcher.toJSON(this,"requirdStringScript")
				.replaceAll("[{] '", "{ ")
				.replaceAll("' : ", " : ")
				.replaceAll(" , '", " , ");
		}
	}
	

}
